import { createRouter, createWebHashHistory } from 'vue-router'
function beforeEnter(to:any, from:any, next:any) {
  const token = localStorage.getItem('token')
  if (token === 'null'||token === ''||token === 'undefined') {
    next('/')
    console.error('token', token,to, from)
    return
  }
  next()
}
const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/tab',
      name: 'tab',
      component: () => import('../components/tab/tab.vue'),
      children: [
        {
          path: '/home',
          name: 'home',
          beforeEnter: beforeEnter,
          component: () => import('../views/HomeView.vue')
        },
        {
          path: '/task',
          name: 'task',
          beforeEnter: beforeEnter,
          component: () => import('../views/TaskView.vue')
        },
        {
          path: '/profile',
          beforeEnter: beforeEnter,
          name: 'profile',
          component: () => import('../views/ProfileView.vue')
        }
      ]
    },
    {
      path: '/setting',
      name: 'setting',
      beforeEnter: beforeEnter,
      component: () => import('../views/SettingView.vue')
    },
    {
      path: '/suggest',
      name: 'suggest',
      beforeEnter: beforeEnter,
      component: () => import('../views/SuggestView.vue')
    },
    {
      path: '/withdraw',
      name: 'withdraw',
      beforeEnter: beforeEnter,
      component: () => import('../views/WithdrawView.vue')
    },
    {
      path: '/withdraw-list',
      name: 'withdraw-liist',
      beforeEnter: beforeEnter,
      component: () => import('../views/WithdrawListView.vue')
    },
    {
      path: '/order',
      name: 'order',
      beforeEnter: beforeEnter,
      component: () => import('../views/OrderView.vue')
    },
    {
      path: '/integral',
      name: 'integral',
      beforeEnter: beforeEnter,
      component: () => import('../views/IntegralView.vue')
    },
    {
      path: '/team',
      beforeEnter: beforeEnter,
      name: 'team',
      component: () => import('../views/TeamView.vue')
    },
    {
      path: '/share',
      beforeEnter: beforeEnter,
      name: 'share',
      component: () => import('../views/ShareView.vue')
    },
    {
      path: '/msg-detail',
      beforeEnter: beforeEnter,
      name: 'msg-detail',
      component: () => import('../views/MsgDetailView.vue')
    },
    {
      path: '/login',
      name: 'login',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/LoginView.vue')
    },
    {
      path: '/register',
      name: 'register',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import('../views/RegisterView.vue')
    },

    { path: '/', redirect: '/login' }
  ]
})

export default router
